<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    $(function() {
        $('#craftsmanEditForm').form({
            url : '${path}/craftsman/edit',
            onSubmit : function() {
                progressLoad();
                var isValid = $(this).form('validate');
                if (!isValid) {
                    progressClose();
                }
                return isValid;
            },
            success : function(result) {
                progressClose();
                result = $.parseJSON(result);
                if (result.success) {
                    parent.$.modalDialog.openner_dataGrid.datagrid('reload');//之所以能在这里调用到parent.$.modalDialog.openner_dataGrid这个对象，是因为user.jsp页面预定义好了
                    parent.$.modalDialog.handler.dialog('close');
                } else {
                    var form = $('#craftsmanEditForm');
                    parent.$.messager.alert('错误', eval(result.msg), 'error');
                }
            }
        });
        
        $("#manName").val('${craftsman.manName}'); 
        
    });
    //检查图片的格式是否正确,同时实现预览  
    function setImagePreview(obj, localImagId, imgObjPreview,maxwidth,maxheight) {  
        var array = new Array('gif', 'jpeg', 'png', 'jpg', 'bmp'); //可以上传的文件类型  
        if (obj.value == '') {  
            $.messager.alert("让选择要上传的图片!");  
            return false;  
        }  
        else {  
            var fileContentType = obj.value.match(/^(.*)(\.)(.{1,8})$/)[3]; //这个文件类型正则很有用   
            ////布尔型变量  
            var isExists = false;  
            //循环判断图片的格式是否正确  
            for (var i in array) {  
                if (fileContentType.toLowerCase() == array[i].toLowerCase()) {  
                    //图片格式正确之后，根据浏览器的不同设置图片的大小  
                    if (obj.files && obj.files[0]) {  
                        //火狐下，直接设img属性   
                        imgObjPreview.style.display = 'block';  
                        imgObjPreview.style.width = maxwidth;  
                        imgObjPreview.style.height = maxheight;  
                        //火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式   
                        imgObjPreview.src = window.URL.createObjectURL(obj.files[0]);  
                    }  
                    else {  
                        //IE下，使用滤镜   
                        obj.select();  
                        var imgSrc = document.selection.createRange().text;  
                        //必须设置初始大小   
                        localImagId.style.width = maxheight;  
                        localImagId.style.height = maxheight;  
                        //图片异常的捕捉，防止用户修改后缀来伪造图片   
                        try {  
                            localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";  
                            localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;  
                        }  
                        catch (e) {  
                            $.messager.alert("您上传的图片格式不正确，请重新选择!");  
                            return false;  
                        }  
                        imgObjPreview.style.display = 'none';  
                        document.selection.empty();  
                    }  
                    isExists = true;  
                    return true;  
                }  
            }  
            if (isExists == false) {  
                $.messager.alert("上传图片类型不正确!");  
                return false;  
            }  
            return false;  
        }  
    }  
  
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false" title="" style="overflow:scroll;padding: 3px;">
        <form id="craftsmanEditForm" method="post" enctype="multipart/form-data" >
        	<input name="id" type="hidden"  value="${craftsman.id}">
            <table class="grid" >
	            <tr>
	             	<td style="background-color:#eb8787;" colspan="4" align="center">
	             		基本信息
	             	</td>
	            </tr>
	            <tr>
                    <td style="width:130px;">姓名</td>
                    <td style="width:200px;">
                    	<input name="manName" type="text" placeholder="请输入姓名" class="easyui-validatebox" data-options="required:true" value="${craftsman.manName}">
                    </td>
                    <td width="100px" rowspan="6">照片</td>
                    <td rowspan="6">
						<div id="localImag">  
						    <%--预览，默认图片--%>
						    <c:if test="${not empty craftsman.manPhoto}">
								<img id="preview" alt="预览图片"  src="${craftsman.manPhoto}" style="width: 150px; height: 170px;"/>   
							</c:if>
							<c:if test="${empty craftsman.manPhoto}">
								<img id="preview" alt="预览图片"  src="/static/style/images/bg_head.png" style="width: 150px; height: 170px;"/>   
							</c:if>  
						</div>  
                    	    选择图片:<input id="idFile" name="pic_manPhoto" onchange="javascript:setImagePreview(this,localImag,preview,'150px','170px');" type="file" />
                    	    <input id="manPhoto" name="manPhoto"  type="hidden" value="${craftsman.manPhoto}"/>  
                    </td>
                </tr>
                 <tr>
                    <td>性别</td>
                    <td >
                    	<input type="radio" name="manSex" value="0" <c:if test="${craftsman.manSex eq 0}">checked="checked"</c:if> />女
                		<input type="radio" name="manSex" value="1" <c:if test="${craftsman.manSex eq 1}">checked="checked"</c:if>/>男
                    </td>
                </tr>
                <tr>
                    <td>出生日期</td>
                    <td>
                    	<input class="easyui-datebox" id="manBirthday" name="manBirthday" value="${craftsman.manBirthday}"></input>
                    </td>
                </tr>
                <tr>
                    <td>居住城市</td>
                    <td >
                    	<input name="manCity" type="text" placeholder="居住城市" class="easyui-validatebox" value="${craftsman.manCity}">
                    </td>
                </tr>
                <tr>
                    <td>证件类型</td>
                    <td>
                    	<select name="manIdtype" >
                    		<option>---</option>
                    		<option value="1" <c:if test="${craftsman.manIdtype eq 1}">selected="selected"</c:if>>身份证</option>
                    		<option value="2" <c:if test="${craftsman.manIdtype eq 2}">selected="selected"</c:if>>护照</option>
                    	</select>
                    </td>
                </tr>
                <tr>
                    <td>证件号码</td>
                    <td >
                    	<input name="manIdnum" type="text" placeholder="证件号码" class="easyui-validatebox" value="${craftsman.manIdnum}">
                    </td>
                </tr>
                <tr>
	             	<td style="background-color:#eb8787;" colspan="4" align="center">
	             		联系方式
	             	</td>
	            </tr>
	            <tr>
	            	<td>手机</td>
                    <td>
                    	<input name="manCellphone" type="text" placeholder="手机号" class="easyui-validatebox"  value="${craftsman.manCellphone}">
                    </td>
                    <td>座机</td>
                    <td>
                    	<input name="manTelephone" type="text" placeholder="座机号" class="easyui-validatebox"  value="${craftsman.manTelephone}">
                    </td>
	            </tr>
	            <tr>
	            	<td>邮箱</td>
                    <td>
                    	<input name="manEmail" type="text" class="easyui-validatebox"  value="${craftsman.manEmail}">
                    </td>
                    <td>微信</td>
                    <td>
                    	<input name="manWeixin" type="text" class="easyui-validatebox"  value="${craftsman.manWeixin}">
                    </td>
	            </tr>
	            <tr>
	            	<td>QQ</td>
                    <td>
                    	<input name="manQq" type="text" class="easyui-validatebox"  value="${craftsman.manQq}">
                    </td>
                    <td>微博</td>
                    <td>
                    	<input name="manWeibo" type="text" class="easyui-validatebox" value="${craftsman.manWeibo}">
                    </td>
	            </tr>
	            <tr>
	            	<td>个人主页</td>
                    <td colspan="3">
                    	<input style="width:525px" name="manHomepage" type="text" class="easyui-validatebox" value="${craftsman.manHomepage}">
                    </td>
	            </tr>
	            <tr>
	             	<td style="background-color:#eb8787;" colspan="4" align="center">
	             		教育及方向
	             	</td>
	            </tr>
	            <tr>
	            	<td>毕业院校</td>
                    <td>
                    	<input name="manSchool" type="text" class="easyui-validatebox"  value="${craftsman.manSchool}">
                    </td>
                    <td>最高学历</td>
                    <td>
                    	<input name="manEducation" type="text" class="easyui-validatebox" value="${craftsman.manEducation}">
                    </td>
	            </tr>
	            <tr>
	            	<td>现任职务</td>
                    <td>
                    	<input name="manPosition" type="text" class="easyui-validatebox"  value="${craftsman.manPosition}">
                    </td>
                    <td>主营业务方向</td>
                    <td>
                    	<input name="manBusiness" type="text" class="easyui-validatebox" value="${craftsman.manBusiness}">
                    </td>
	            </tr>
	            <tr>
	            	<td>其他涉猎方向</td>
                    <td colspan="3">
                    	<input style="width:525px" name="manBusinessOther" type="text" class="easyui-validatebox"  value="${craftsman.manBusinessOther}">
                    </td>
	            </tr>
	            <tr>
	            	<td>个人简介</td>
                    <td colspan="3">
                    	<textarea rows="5" cols="80" name="manIntroduction">${craftsman.manIntroduction}</textarea>
                    </td>
	            </tr>
	            <tr>
	             	<td style="background-color:#eb8787;" colspan="4" align="center">
	             		公司信息
	             	</td>
	            </tr>
	            <tr>
	            	<td>公司名称</td>
                    <td>
                    	<input name="manCompany" type="text" class="easyui-validatebox"  value="${craftsman.manCompany}">
                    </td>
                    <td rowspan="3">LOGO</td>
                    <td rowspan="3">
						<div id="localImag1">  
						    <c:if test="${not empty craftsman.manCompanyLogo}">
								<img id="preview1" alt="预览图片"  src="${craftsman.manCompanyLogo}" style="width: 150px; height: 170px;"/>   
							</c:if>
							<c:if test="${empty craftsman.manCompanyLogo}">
								<img id="preview1" alt="预览图片"  src="/static/style/images/hui.jpg" style="width: 150px; height: 170px;"/>   
							</c:if>  
						</div>  
                    	    选择图片:<input id="idFile1" name="pic_manCompanyLogo" onchange="javascript:setImagePreview(this,localImag1,preview1,'150px','170px');" type="file" />
                    	<input id="pic_manCompanyLogo" name="pic_manCompanyLogo"  type="hidden" value="${craftsman.manCompanyLogo}"/>  
                    </td>
	            </tr>
	            <tr>
	            	<td>公司电话</td>
                    <td>
                    	<input name="manCompanyPhone" type="text" class="easyui-validatebox"  value="${craftsman.manCompanyPhone}">
                    </td>
	            </tr>
	            <tr>
	            	<td>公司所在地</td>
                    <td>
                    	<input name="manCompanyAdddress" type="text" class="easyui-validatebox" value="${craftsman.manCompanyAdddress}">
                    </td>
	            </tr>
	            <tr>
	            	<td>官网地址</td>
                    <td colspan="3">
                    	<input style="width:525px" name="manHaswebsite" type="text" class="easyui-validatebox" value="${craftsman.manHaswebsite}">
                    </td>
	            </tr>
	            <tr>
	            	<td>网店地址</td>
                    <td colspan="3">
                    	<input style="width:525px" name="manHaswebshop" type="text" class="easyui-validatebox"  value="${craftsman.manHaswebshop}">
                    </td>
	            </tr>
	            <tr>
	             	<td style="background-color:#eb8787;" colspan="4" align="center">
	             		公司品牌及产品
	             	</td>
	            </tr>
	            <tr>
	            	<td>品牌名称</td>
                    <td>
                    	<input name="manBrand" type="text" class="easyui-validatebox"  value="${craftsman.manBrand}">
                    </td>
                    <td rowspan="2">LOGO</td>
                    <td rowspan="2">
						<div id="localImag2">  
							<c:if test="${not empty craftsman.manBrandLogo}">
								<img id="preview2" alt="预览图片"  src="${craftsman.manBrandLogo}" style="width: 150px; height: 170px;"/>   
							</c:if>
							<c:if test="${empty craftsman.manBrandLogo}">
								<img id="preview2" alt="预览图片"  src="/static/style/images/hui.jpg" style="width: 150px; height: 170px;"/>   
							</c:if>
						</div>  
                    	    选择图片:<input id="idFile2" name="pic_manBrandLogo" onchange="javascript:setImagePreview(this,localImag2,preview2,'150px','170px');" type="file" />
                    	    <input id="manBrandLogo" name="manBrandLogo"  type="hidden" value="${craftsman.manBrandLogo}"/>    
                    </td>
	            </tr>
	            <tr>
	            	<td>品牌唯一标识</td>
                    <td>
                    	<input required="required" name="manKey" type="text" class="easyui-validatebox"  value="${craftsman.manKey}">
                    </td>
	            </tr>
	            <tr>
	            	<td>品牌简介</td>
                    <td colspan="3">
                    	<textarea rows="3" cols="80" name="manBrandinfo" >${craftsman.manBrandinfo}</textarea>
                    </td>
	            </tr>
	            <tr>
	            	<td>微博</td>
                     <td colspan="3">
                    	<input style="width:525px" name="manCompanyweibo" type="text" class="easyui-validatebox"  value="${craftsman.manCompanyweibo}">
                    </td>
	            </tr>
	            <tr>
	            	<td>微信公众号</td>
                     <td colspan="3">
                    	<input style="width:525px" name="manCompanyweixin" type="text" class="easyui-validatebox"  value="${craftsman.manCompanyweixin}">
                    </td>
	            </tr>
	            <tr>
	            	<td>宣传视频</td>
                     <td colspan="3">
                    	<input style="width:525px" name="manCompanyvedio" type="text" class="easyui-validatebox"  value="${craftsman.manCompanyvedio}">
                    </td>
	            </tr>
	            
            </table>
        </form>
    </div>
</div>